const { defineConfig } = require("@vue/cli-service");
const path = require("path");
const { name } = require("./package");
const config = require("./config/dev.config");

function resolve(dir) {
  return path.join(__dirname, dir);
}

const isProd = process.env.NODE_ENV === "production";
const proxySetting = () => {
  if (!config.useMock && !isProd) {
    return {
      proxy: config.devServer.proxy,
    };
  }
  return {};
};
const port = config.devServer.port;
module.exports = defineConfig({
  lintOnSave: process.env.NODE_ENV !== "production",
  productionSourceMap: false,
  devServer: {
    hot: true,
    allowedHosts: "all",
    port,
    client: {
      overlay: {
        errors: true,
        warnings: false,
      },
    },
    headers: {
      "Access-Control-Allow-Origin": "*",
    },
    ...proxySetting(),
  },
  // 自定义webpack配置
  configureWebpack: {
    resolve: {
      alias: {
        "@": resolve("src"),
      },
    }
  },
  chainWebpack: (config) => {
    const svgRule = config.module.rule("svg");
    svgRule.uses.clear();
    svgRule.use("vue-svg-loader").loader("vue-svg-loader");
    // config.mode('development')
  },
});
